package netWorkPrograming.tcp.tcp01;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
import java.util.zip.GZIPOutputStream;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/27
 * 需求1：客户端与服务端可以建立连接 ； 服务端接收一条消息，客户端发送一条消息
 */
public class ClientDemo {
    public static void main(String[] args) {
        System.out.println("-----------客户端-----------");
        Socket socket = null;
        Scanner sc = new Scanner(System.in);;
        PrintWriter pw = null;
        try {
            socket=new Socket("127.0.0.1",8888);
            System.out.println("请输入要说的话：");
            String input=sc.nextLine();
            pw=new PrintWriter(socket.getOutputStream(),true);
            pw.println(input);
        }catch (IOException e) {
            throw new RuntimeException(e);
        }finally{
            if(sc!=null) sc.close();
            if(pw!=null) pw.close();
            if(socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
